package cn.itheima.service.system.impl;

import cn.itheima.dao.PermissionRepository;
import cn.itheima.domain.system.Permission;
import cn.itheima.domain.system.User;
import cn.itheima.service.system.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by millions on 2017/7/20.
 */
@Service
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    private PermissionRepository permissionRepository;

    @Override
    public List<Permission> findByUser(User user) {
        if (user.getUsername().equals("admin")) {
            return permissionRepository.findAll();
        } else {
            return permissionRepository.findByUser(user.getId());
        }
    }
}
